using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using btnet;

/// <summary>
/// Summary description for query (query_class)
/// </summary>
public partial class query_class : System.Web.UI.Page
{
    protected DataSet ds;
    protected Security security;
    protected string exception_message;

    ///////////////////////////////////////////////////////////////////////
    void Page_Load(Object sender, EventArgs e)
    {

        Util.do_not_cache(Response);


        // If there is a users table, then authenticate this page
        try
        {
            btnet.DbUtil.execute_nonquery("select count(1) from users");
            security = new Security();
            security.check_security(HttpContext.Current, Security.MUST_BE_ADMIN);
        }
        catch (Exception)
        {
        }

        titl.InnerText = Util.get_setting("AppTitle", "BugTracker.NET") + " - "
            + "run query";


        if (IsPostBack)
        {
            if (query.Value != "")
            {
                try
                {
                    ds = btnet.DbUtil.get_dataset(Server.HtmlDecode(query.Value));
                }
                catch (Exception e2)
                {
                    exception_message = e2.Message;
                    //exception_message = e2.ToString();  // uncomment this if you need more error info.
                }
            }
        }
        else
        {
            DataSet ds = btnet.DbUtil.get_dataset("select name from sysobjects where type = 'u' order by 1");
            dbtables_select.Items.Add("Select Table");
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                dbtables_select.Items.Add((string)dr[0]);
            }
        }
    }

}